package datatype;

import java.util.ArrayList;

/**
 * Created by kevin on 15-1-4.
 */
public class List {
    public Item start = null;
    private class Item{
        private int value;
        private Item next;
        private Item(int x,Item item){
            value = x;
            next = item;
        }
    }
    public void insertAfter(Item item,int x){
        if(item == null){
            start = new Item(x,start);
        }else {
            item.next = new Item(x,item.next);
        }
    }
    public void deleteAfter(Item item){
        if(item == null){
            start = start.next;
        }else{
            item.next = item.next.next;
        }
    }
    public Item findValue(int x){
        Item p = start;
        while(p!=null&&p.value!=x){
            p = p.next;
        }
        return p;
    }
    public void deleteValue(int x){
        Item previous = null;
        for(Item item = start;item!=null;item = item.next){
            if(item.value == x){
                deleteAfter(previous);
                break;
            }else{
                previous = item;
            }
        }
    }

}
